from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from conf.settings import db_url


# 数据库封装工具
class DBUtil:
    engine = None
    session = None

    def get_engine(self):
        self.engine = create_engine(db_url, echo=False)
        return self.engine
    # 获取会话
    def get_session(self):
        engine = self.get_engine()
        Session = sessionmaker(bind=engine)
        self.session = Session()
        return self.session

    def close(self):
        self.session.close()
        self.engine.dispose()

